/*
		KMC Simulation
		Copyright (c) 2012-2014 Filip Rozbořil

		This program is free software: you can redistribute it and/or modify
		it under the terms of the GNU General Public License as published by
		the Free Software Foundation, either version 3 of the License, or
		(at your option) any later version.

		This program is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
		GNU General Public License for more details.

		You should have received a copy of the GNU General Public License
		along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "includes.h"
#include "Utils.h"

// http://en.wikipedia.org/wiki/MurmurHash
// we only use the finalizer, because the input is always 64bits in length
inline uint64_t fmix(uint64_t k)
{
	k ^= k >> 33;
	k *= UINT64_C(0xff51afd7ed558ccd);
	k ^= k >> 33;
	k *= UINT64_C(0xc4ceb9fe1a85ec53);
	k ^= k >> 33;

	return k;
}

uint64_t Utils :: getPrngKey(uint64_t index)
{
	return fmix(index + 1); //MurmurHash finalizer; incremented by 1 to avoid zero output for zero input
}

#ifdef DEBUG_FAST

#include "CircularBuffer.h"

static CircularBuffer<string> mBuffer(500);

void Utils :: bufferLine(const string& line)
{
	mBuffer.push(line);
}

void Utils :: printBuffer()
{
	while(!mBuffer.isEmpty())
	{
		const string& line = mBuffer.pop();
		cout << line << endl;
	}
}

#endif


